package top.longmarch.flow.test;

import cn.hutool.core.map.MapUtil;
import cn.hutool.json.JSONObject;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

@Slf4j
@LiteflowComponent(id = "ACmp", name = "ACmp")
public class ACmp extends NodeComponent {

    @Override
    public void process() throws Exception {
        log.info("ACmp executed!");
        Map<String, Object> req = this.getRequestData();
        JSONObject context = this.getContextBean(JSONObject.class);
        Integer x = MapUtil.getInt(req, "x");
        if (x == null) {
            throw new RuntimeException("x is null");
        }
        Integer y = MapUtil.getInt(req, "y");
        if (y == null) {
            throw new RuntimeException("y is null");
        }
        context.set("x", x);
        context.set("y", y);
    }

}
